package com.managertrade.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class LeadTraderCurrentPositionsResponseDTO {

    /** 返回码，0表示成功 */
    @JsonProperty("code")
    private String code;

    /** 返回信息 */
    @JsonProperty("msg")
    private String msg;

    /** 当前持仓数据列表 */
    @JsonProperty("data")
    private List<Position> data;

    // getter & setter
    public String getCode() { return code; }
    public void setCode(String code) { this.code = code; }

    public String getMsg() { return msg; }
    public void setMsg(String msg) { this.msg = msg; }

    public List<Position> getData() { return data; }
    public void setData(List<Position> data) { this.data = data; }

    /**
     * 内部类映射每个交易员当前持仓
     */
    public static class Position {

        /** 币种，例如 USDT */
        @JsonProperty("ccy")
        private String ccy;

        /** 产品ID，例如 ETH-USDT-SWAP */
        @JsonProperty("instId")
        private String instId;

        /** 产品类型，SPOT：币币交易，SWAP：永续合约 */
        @JsonProperty("instType")
        private String instType;

        /** 杠杆倍数 */
        @JsonProperty("lever")
        private String lever;

        /** 保证金 */
        @JsonProperty("margin")
        private BigDecimal margin;

        /** 最新标记价格，仅适用于合约 */
        @JsonProperty("markPx")
        private BigDecimal markPx;

        /** 保证金模式，isolated：逐仓；cross：全仓 */
        @JsonProperty("mgnMode")
        private String mgnMode;

        /** 开仓均价 */
        @JsonProperty("openAvgPx")
        private BigDecimal openAvgPx;

        /** 开仓时间，时间戳（毫秒） */
        @JsonProperty("openTime")
        private Long openTime;
        public void setOpenTime(Long openTime) {
            this.openTime = openTime;
            if (openTime != null) {
                this.openTimeString = LocalDateTime.ofInstant(Instant.ofEpochMilli(openTime), ZoneId.systemDefault())
                        .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            } else {
                this.openTimeString = null;
            }
        }
        private String openTimeString;



        /** 持仓方向
         * long：开平仓模式开多
         * short：开平仓模式开空
         * net：买卖模式（subPos为正代表开多，subPos为负代表开空）
         */
        @JsonProperty("posSide")
        private String posSide;

        /** 持仓张数 */
        @JsonProperty("subPos")
        private String subPos;

        /** 带单仓位ID */
        @JsonProperty("subPosId")
        private String subPosId;

        /** 交易员唯一标识代码 */
        @JsonProperty("uniqueCode")
        private String uniqueCode;

        /** 未实现收益 */
        @JsonProperty("upl")
        private BigDecimal upl;

        /** 未实现收益率 */
        @JsonProperty("uplRatio")
        private BigDecimal uplRatio;

        // getter & setter
        public String getCcy() { return ccy; }
        public void setCcy(String ccy) { this.ccy = ccy; }

        public String getInstId() { return instId; }
        public void setInstId(String instId) { this.instId = instId; }

        public String getInstType() { return instType; }
        public void setInstType(String instType) { this.instType = instType; }

        public String getLever() { return lever; }
        public void setLever(String lever) { this.lever = lever; }

        public BigDecimal getMargin() { return margin; }
        public void setMargin(BigDecimal margin) { this.margin = margin; }

        public BigDecimal getMarkPx() { return markPx; }
        public void setMarkPx(BigDecimal markPx) { this.markPx = markPx; }

        public String getMgnMode() { return mgnMode; }
        public void setMgnMode(String mgnMode) { this.mgnMode = mgnMode; }

        public BigDecimal getOpenAvgPx() { return openAvgPx; }
        public void setOpenAvgPx(BigDecimal openAvgPx) { this.openAvgPx = openAvgPx; }

        public Long getOpenTime() { return openTime; }

        public String getPosSide() { return posSide; }
        public void setPosSide(String posSide) { this.posSide = posSide; }

        public String getSubPos() { return subPos; }
        public void setSubPos(String subPos) { this.subPos = subPos; }

        public String getSubPosId() { return subPosId; }
        public void setSubPosId(String subPosId) { this.subPosId = subPosId; }

        public String getUniqueCode() { return uniqueCode; }
        public void setUniqueCode(String uniqueCode) { this.uniqueCode = uniqueCode; }

        public BigDecimal getUpl() { return upl; }
        public void setUpl(BigDecimal upl) { this.upl = upl; }

        public BigDecimal getUplRatio() { return uplRatio; }
        public void setUplRatio(BigDecimal uplRatio) { this.uplRatio = uplRatio; }
    }
}
